import 'HomeDetail/ProductDetailPage.dart';
import 'package:flutter/material.dart';

class OrderListPage extends StatefulWidget {
  @override
  _OrderListPageState createState() => _OrderListPageState();
}

class _OrderListPageState extends State<OrderListPage> {
  @override
  Widget build(BuildContext context) {
    double totalCost = 0;
    for (var product in orderList) {
      totalCost += product.price;
    }

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.blueGrey,
        title: Text('订单列表'),
      ),
      body: Column(
        children: [
          Expanded(
            child: ListView.builder(
              itemCount: orderList.length,
              itemBuilder: (context, index) {
                return ListTile(
                  leading: Image.asset(orderList[index].imageUrl),
                  title: Text(orderList[index].title),
                  subtitle: Text('价格: ' + orderList[index].price.toString()),
                  trailing: IconButton(
                    icon: Icon(Icons.delete),
                    onPressed: () {
                      setState(() {
                        orderList.removeAt(index);
                      });
                    },
                  ),
                );
              },
            ),
          ),
          Container(
            padding: EdgeInsets.all(16.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text('合计: ' + totalCost.toString()),
                ElevatedButton(
                  onPressed: () {
                    // 购买逻辑
                  },
                  child: Text('购买'),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}